package mis.ds.ps.model.dao.impl;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

import mis.ds.ps.model.dao.DisciplinasDao;
import mis.ds.ps.model.obj.Disciplinas;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.stereotype.Repository;

import com.felees.hbnpojogen.persistence.impl.GenericHibernateDaoImpl;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

/**
 * DAO for table: Disciplinas.
 * 
 * @author autogenerated
 */
@Repository
public class DisciplinasDaoImpl extends GenericHibernateDaoImpl<Disciplinas, Long> implements DisciplinasDao {

	private static Logger logger = Logger.getLogger(DisciplinasDaoImpl.class);

	private Connection mysqlConn;

	/** Constructor method. */
	public DisciplinasDaoImpl() {
		super(Disciplinas.class);

		PropertyConfigurator.configure("log4j.properties");
	}

	public boolean insertDisciplina(Disciplinas disciplina) {
		return false;
	}

	public int insertDisciplinas(List<Disciplinas> disciplinas) {

		int totalInsert = 0;
		String sql = "INSERT disciplinas(NOME) VALUES(?)";
		PreparedStatement prest;
		try {
			for (Iterator<Disciplinas> it = disciplinas.iterator(); it.hasNext();) {
				Disciplinas disciplina = it.next();

				prest = (PreparedStatement) mysqlConn.prepareStatement(sql);
//				prest.setString(1, null);
				prest.setString(1, disciplina.getNome());
				logger.debug("SQL insert statement " + prest.toString());
				int count = prest.executeUpdate();
				totalInsert += count;
			}
			logger.debug("Inseridos " + totalInsert + " no total");
		} catch (SQLException e1) {
			logger.debug("Cannot insert disciplinas on DB ", e1);
		}

		return 0;
	}

	public boolean updateDocente() {
		return false;
	}

	public boolean removeDocente() {
		return false;
	}

	public Connection getMysqlConn() {
		return mysqlConn;
	}

	public void setMysqlConn(Connection mysqlConn) {
		this.mysqlConn = mysqlConn;
	}
}
